import { setToken,getToken,delToken } from "@/utils/storage";

const state = {
  token: getToken() || '',
  username:''
};

const mutations = {
  deleTokena(state,payload) {
    delToken()
    state.token = ''
  },
  setTokena(state, token) {
    console.log(token);
    setToken(token);
    state.token = token
  },
  setUsername(state,payload) {
    state.username = payload
  }
};
const actions = {
  deleToken(context, token) {
    context.commit("deleTokena");
  },
  setToken(context, res) {
    console.log(1);
    context.commit("setTokena", res.token);
    context.commit("setUsername", res.userName);
    console.log(res.userName);
  },
};
export default {
  namespaced: true,
  state,
  mutations,
  actions,

};
